<?php
class Welcome extends AdminAction{
	function index(){
		$sysinfo = loadData('sysinfo.php'); 
		$this->data['title'] = $sysinfo['sys_name'].' - 登入';
		template('welcome',$this->data);
	}
	
	function login(){
		$db = $this->getDB();
		
		$username = P('username');
		$userpass = P('userpass');
		$rember = P('rember');
		
		$user = $db->get_assoc("select id,login_name,login_pass from sys_user where login_name = '$username'");
		
		if(empty($user)){
			$this->ajaxMsg('error','用户名不存在！');
		}else{
			if($user['login_pass'] == $userpass){
				unset($user['login_pass']);
				//用户登入成功
				if($rember == 1){
					setCk('adminlogin',$user['id'].','.$user['login_name'].','.$user['login_pass'],time()+3600*24*30);
				}
				print_r($user);
				setSession('adminlogin', $user);
				
				$this->ajaxMsg('success','用户名登入成功！');
				
			}else{
				//密码错误
				$this->ajaxMsg('error','密码输入错误！');
			}
		}
	}
	
	function console(){
		$user = getSession('adminlogin');
		if(!empty($user)){
			//进入控制台
			
			$this->data['selectitem'] = 'control'; 
			
			template('console',$this->data);
		}else{
			//弹出
			header('location:/admin.php');
		}
		
	}
	
}